set more off
clear all

cap log close
log using an_table1,t replace

use enia_inno_ip_ex, clear

*** Table 1

gen enia = totrev~=.

preserve
keep if enia
sort id year
gen first = id~=id[_n-1]
tab year first

foreach x in pat des um tm {
  gen d`x' = napp_`x'>0
  egen x = sum(napp_`x'),by(id)
  gen unique`x' = x>0
  drop x
  count if unique`x' & first
  egen ny_`x' = sum(d`x'), by(id)
  tab ny_`x' if first & ny_`x'>0
  }
gen all = 1
count if all & first
collapse (sum) all dpat ddes dtm dum, by(year)
list year all dpat ddes dum dtm, clean noobs
restore

*** restricted to innovation sample
preserve
keep if innosmpl
sort id year
gen first = id~=id[_n-1]
foreach x in pat des um tm {
  gen d`x' = napp_`x'>0
  egen x = sum(napp_`x'),by(id)
  gen unique`x' = x>0
  drop x
  count if unique`x' & first
  }
gen all = 1
count if all & first
collapse (sum) all dpat ddes dtm dum, by(year)
list year all dpat ddes dum dtm, clean noobs
restore

preserve
keep if innosmpl & enia
sort id year
gen first = id~=id[_n-1]
foreach x in pat des um tm {
  gen d`x' = napp_`x'>0
  egen x = sum(napp_`x'),by(id)
  gen unique`x' = x>0
  drop x
  count if unique`x' & first
  }
gen all = 1
count if all & first
collapse (sum) all dpat ddes dtm dum, by(year)
list year all dpat ddes dum dtm, clean noobs
restore

log close
